package com.gab.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gab.mapper.TbRecruitMapper;
import com.gab.service.TbRecruitService;
import com.gab.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import  com.gab.pojo.TbRecruitExample;
import  com.gab.pojo.TbRecruitExample.Criteria;
import com.gab.pojo.TbRecruit;

@Service
public class TbRecruitServiceImpl  implements TbRecruitService{
	@Autowired
	private TbRecruitMapper tbRecruitMapper;
	
	public List<TbRecruit> findAll() {
		// TODO Auto-generated method stub
		return tbRecruitMapper.selectByExample(null);
	}

	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);		
		Page<TbRecruit> page=   (Page<TbRecruit>) tbRecruitMapper.selectByExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	public void add(TbRecruit tbRecruit) {
		tbRecruitMapper.insert(tbRecruit);
		
	}

	public void update(TbRecruit tbRecruit) {
		tbRecruitMapper.updateByPrimaryKey(tbRecruit);
		
	}

	public TbRecruit findOne(Long id) {
		
		return tbRecruitMapper.selectByPrimaryKey(id);
	}

	public void delete(Long[] ids) {
		for(Long id:ids){
			tbRecruitMapper.deleteByPrimaryKey(id);
		}
		
	}

	public PageResult findPage(TbRecruit tbRecruit, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
		
		TbRecruitExample example=new TbRecruitExample();
		Criteria criteria = example.createCriteria();
		
		if(tbRecruit!=null){			
			if(tbRecruit.getContent()!=null && tbRecruit.getContent().length()>0){
				criteria.andContentLike("%"+tbRecruit.getContent()+"%");
			}
			
	
		}
		
		Page<TbRecruit> page= (Page<TbRecruit>)tbRecruitMapper.selectByExample(example);		
		return new PageResult(page.getTotal(), page.getResult());
	}

}
